const recursion = {
    convertTree: function(tree, map) {
        const result = [];
        tree.forEach((item) => {
        //     // 读取 map 的键值映射
        //     let value = item[ map.value ];
        //     let label = item[ map.label ];
        //     let children = item[ map.children ];
        //     // 如果有子节点，递归
        //     if (children) {
        //         children = this.convertTree(children, map);
        //     }
        //     result.push({ id:item.id, children, value, label  });

            for (let [key,value] of Object.entries(map)){
                item[key] = item[value]
                if  (item.children && item.children.length)
                    this.convertTree(item.children, map);
                   }
            if (!(item.children && item.children.length)){
                delete item.children
            }
        })
        return tree
    },
    treeFindPath: function (tree, func, path = []) {
        if (!tree) return []
        for (const data of tree) {
            path.push(data.value)
            if (func(data)) return path
            if (data.children) {
                const findChildren = this.treeFindPath(data.children, func, path)
                if (findChildren.length) return findChildren
            }
            path.pop()
        }
        return []
    }
}
export default recursion
